package structure.hash.test;

import structure.hash.basic.MyHashMap;
import structure.hash.basic.MyHashSet;
import structure.hash.basic.MyLinkedHashMap;
import structure.hash.basic.MyMap;


import java.util.LinkedHashMap;

/**
 * 项目名称: god
 * 包 名 称: structure.hash.test
 * 类 名 称: Main
 * 类 描 述: TODO
 * 创建时间: 2020/6/15 9:59 上午
 * 创 建 人: Justice
 */
public class Main {
    public static void main(String[] args) {
        test4();
    }

    private static void test() {
        // 整数
        int a = 10;
        System.out.println(Integer.hashCode(a));
        // 浮点数
        float b = 100f;
        System.out.println(Float.floatToIntBits(b));
        long c = 99L;
        System.out.println(Long.hashCode(c));
        double d = 9.9;
        System.out.println(Double.hashCode(d));
        String e = "hello";
        System.out.println(e.hashCode());
    }

    private static void test1() {
        MyHashMap<Integer, Integer> myHashMap = new MyHashMap<>();
        for (int i = 0; i < 10; i++) {
            myHashMap.put(i, i * i);
        }
        // System.err.println(myHashMap.get(4));
        myHashMap.remove(1);
        System.out.println(myHashMap.containsKey(1));
        System.out.println(myHashMap.containsValue(16));
    }

    private static void test2() {
//        HashMap<Integer, Integer> hashMap = new HashMap<>();
//        hashMap.put(4, 5);
//        hashMap.put(1, 2);
//        hashMap.put(5, 6);
//        hashMap.put(2, 3);
//        hashMap.put(7, 8);
//        hashMap.put(3, 4);
//        hashMap.put(6, 7);
//        for (Integer integer : hashMap.keySet()) {
//            System.out.println(integer + ":" + hashMap.get(integer));
//        }
        LinkedHashMap<Integer, Integer> linkedHashMap = new LinkedHashMap<>();
        linkedHashMap.put(4, 5);
        linkedHashMap.put(1, 2);
        linkedHashMap.put(5, 6);
        linkedHashMap.put(2, 3);
        linkedHashMap.put(7, 8);
        linkedHashMap.put(3, 4);
        linkedHashMap.put(6, 7);
        for (Integer integer: linkedHashMap.keySet()){
            System.out.println(integer + ":" + linkedHashMap.get(integer));
        }
    }

    private static void test3() {
        MyLinkedHashMap<Integer, Integer> myLinkedHashMap = new MyLinkedHashMap<>();
        myLinkedHashMap.put(10, 1);
        myLinkedHashMap.put(1, 1);
        myLinkedHashMap.put(2, 1);
        myLinkedHashMap.put(3, 1);
        myLinkedHashMap.traversal(new MyMap.Visitor<Integer, Integer>() {
            @Override
            public boolean visit(Integer key, Integer value) {
                System.out.println(key + ":" + value);
                return false;
            }
        });
    }

    private static void test4(){
        MyHashSet<Integer> myHashSet = new MyHashSet<>();
        myHashSet.add(1);
        myHashSet.add(1);
        System.out.println(myHashSet.size());
    }
}
